﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace demo
{
    public static class CopyFileTools
    {
        private const int BufferSize = 10240; // 10 KB

        public static void CopyFile(string fileName, string copyName)
        {
            using (Stream source = new FileStream(fileName, FileMode.Open, FileAccess.Read))
            {
                using (Stream target = new FileStream(copyName, FileMode.Create, FileAccess.Write))
                {
                    byte[] buffer = new byte[BufferSize];
                    int bytesRead;
                    do
                    {
                        // 从源文件中读取指定的10K长度到缓存中
                        bytesRead = source.Read(buffer, 0, BufferSize);
                        // 从缓存中写入已读取到的长度到目标文件中
                        target.Write(buffer, 0, bytesRead);
                    } while (bytesRead > 0);
                }
            }
        }
    }
}